package top.kaoshanji.p1ch03a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * 代码清单 p1ch03a-14：锁定文件的示例
 * 并未运行
 * author kaoshanji
 * ^_^
 * create time 2025/1/8 17:59
 */
public class FileChannelExample06 {

    private static final Logger logger = LogManager.getLogger(FileChannelExample06.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch03a-14：锁定文件的示例...");

        // 这个文件不存在
        try (FileChannel channel = FileChannel.open(Paths.get("settings.config"), StandardOpenOption.READ, StandardOpenOption.WRITE);
             FileLock lock = channel.lock()){

            // 更新文件内容

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}
